import http from '@/utils/http';
import { languages } from 'monaco-editor';
import json = languages.json;

interface IGetProblemListRes {
  count: number;
  list: ProblemEasy[];
}

export interface ProblemEasy {
  id: number;
  title: string;
  // eslint-disable-next-line camelcase
  remote_oj: string;
  timeLimit: string;
  rating: number;
  // eslint-disable-next-line camelcase
  remote_id: string;
  // eslint-disable-next-line camelcase
  total_submitted: number;
  // eslint-disable-next-line camelcase
  total_accepted: number;
  // eslint-disable-next-line camelcase
  remote_url: string;
  createTime: Date;
  updateTime: Date;
}

export interface Problem {
  title: string;
  content: {
    description: string;
    hint: string;
    // eslint-disable-next-line camelcase
    input_description: string;
    // eslint-disable-next-line camelcase
    output_description: string;
    // eslint-disable-next-line camelcase
    input_sample: string;
    // eslint-disable-next-line camelcase
    output_sample: string;
    samples: [
      {
        input: string;
        output: string;
      }
    ];
  };
  // eslint-disable-next-line camelcase
  time_limit: string;
  // eslint-disable-next-line camelcase
  memory_limit: string;
  id: number;
  // eslint-disable-next-line camelcase
  remote_id: string;
  // eslint-disable-next-line camelcase
  remote_oj: string;
}

interface ISubmitReq {
  problemId: number;
  code: string;
  lang: string;
}

export interface ISubmitRes {
  submissionId: number;
}

export interface IGetSubmissionByIdReq {
  id: string;
}

export interface SubmissionDetail {

}

export interface ITag {
  name: string;
  color: string;
}


export interface IRemoteProblem {
  name: string;
  rating: number | 0;
  remoteOJ: string;
  remoteId: string;
  remoteUrl: string;
  tags: ITag[];
  solvedCount: number;
  // eslint-disable-next-line camelcase
  is_get_problem_success: boolean;

}

export interface IRemoteOJ {
  id: number;
  name: string;
  picture: string;
  baseurl: string;
  description: string;
}

export const getRemoteOJ = async (id: number) => {
  return (await http.get(`/robot/remoteoj/${id}`)) as IRemoteOJ;
};

export const addRemoteProblem = async (remoteId: string) => {
  return (await http.get(`/problem/${remoteId}`)) as Problem;
};

export const getProblemList = async (page: number, remote ?: number , other ?: object) => {
  let url = '/problem/list/';
  return (await http.get(url, { page: page, remote_oj: remote , ...other })) as IGetProblemListRes | any;
};
export const getRemoteProblemList = async (page: number, pageSize ?: number, remote ?: number, other ?: object) => {
  return (await http.get('/Admin/remoteproblem/list/', {
    page: page,
    page_size: pageSize,
    remote_oj: remote,
    ...other
  }));
};

export const updateRemoteOJProblem = async (remote: number) => {
  return (await http.post('/Admin/remoteproblem/', { remote_oj_id: remote })) as { task: string };
};

export const getAdminProblemList = async (page: number) => {
  return (await http.get(`/problem/list/?page=${page}`)) as IGetProblemListRes | any;
};


export const getProblemById = async (id: number) => {

  return (await http.get(`/problem/${id}`)) as Problem;
};

export const submit = async (data: ISubmitReq) => {
  return (await http.post('/problem/submit/', data)) as ISubmitRes;
};

export const getSubmissionById = async (data: IGetSubmissionByIdReq) => {
  return await http.post('/submission/check/', data);
};
export const getSubmissionDetailById = async (id: number) => {
  return (await http.get(`/submission/check/${id}`)) as SubmissionDetail;
};

export const getSubmissionList = async (problemId: number) => {
  return await http.post('/submission/listUserSubmission/', { problemId });
};

export const getGlobalSubmissionList = async (page: number) => {
  return await http.get(`/submission/list/?page=${page}`);
};

export const addProblem = async (data: any) => {
  return await http.post('/problem/add', data);
};

export const updateProblem = async (id: number, data: any) => {
  return await http.post('/problem/update', { id, data });
};

export const deleteProblem = async (id: number) => {
  return await http.post('/problem/delete', { id });
};
